package com.ideabove.radio;

import com.google.analytics.tracking.android.EasyTracker;
import com.google.android.gcm.GCMRegistrar;
import com.ideabove.data.PushedData;
import com.ideabove.radio.R;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;

public class PushedActivity extends Activity {

	Intent receviedIntent = null;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);                   
//        setContentView(R.layout.layout_intro);
        
        Intent intent = getIntent();
        
        if (intent != null)
        {
        	
	        PushedData obj = (PushedData)intent.getParcelableExtra("pushedData");
	        
	        
	        if("2".equals(obj.getType())){ // type: 0: test, 1: not yet, 2:notice for web
	        	
	        	receviedIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(obj.getValue()));
	        	startActivity(receviedIntent);
				finish();   	        	
	        }
        }
    }
    
    public void initPushService(){
		 // 디바이스 GCM 사용 가능한지 확인
       GCMRegistrar.checkDevice(this);
       // 매니페스트 설정이 올바른지 확인
       GCMRegistrar.checkManifest(this);
       // 등록
       registerToken();       
	}
    
    /**
     * GCM에 디바이스 토큰 등록
     */
    private void registerToken() {
        // registration ID（디바이스 토큰) 취득하고 등록되지 않은 경우 GCM에 등록
        String regId = GCMRegistrar.getRegistrationId(this);
        
        if ("".equals(regId)) {	        	
        	GCMRegistrar.register(this, MainActivity.PUSH_PROJECT_ID);
        }
    }
    
    @Override
	  public void onStart() {
	    super.onStart();
	    // The rest of your onStart() code.
	    EasyTracker.getInstance().activityStart(this); // Add this method.
	  }

	  @Override
	  public void onStop() {
	    super.onStop();
	    // The rest of your onStop() code.
	    EasyTracker.getInstance().activityStop(this); // Add this method.
	  }
	
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    
        return true;
    }
    
    
}
